/**
*      author: Y_Yao
*      created: 2025-01-24 12:19:46
**/

#include<bits/stdc++.h>

#define int LL
using namespace std;
using LL = long long;
const LL LLINF = 1e18;
const int INF = 0x3f3f3f3f;
const int N = 1e9 + 7;
int n,a,b,c;

void solve()
{
    cin >> n >> a >> b >> c;
    int sum = a + b + c;
    int ans = n / sum * 3;
    int re = n % sum;
    if(re == 0)
    {
        cout << ans << endl;
        return;
    }
    ans++;
    re -= a;
    if(re <= 0)
    {
        cout << ans << endl;
        return;
    }
    ans++;
    re -= b;
    if(re <= 0)
    {
        cout << ans << endl;
        return;
    }
    ans++;
    re -= c;
    cout << ans << endl;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}